package conchmusic.conchmusicclient.popupWindow;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.PopupWindow;

import java.util.ArrayList;

import conchmusic.conchmusicclient.R;
import conchmusic.conchmusicclient.mainUi.MainActivity;
import conchmusic.conchmusicclient.mainUi.SurePopup;
import conchmusic.conchmusicclient.mainUi.UpdatePopup;
import conchmusic.conchmusicclient.pojo.SongList;


/**
 * Created by Administrator on 2017/5/12.
 */

public class SongListPopu extends PopupWindow{
    private SurePopup sp;
    private UpdatePopup up;
    private final int posi;
    private View mMenuView;
    private Button cancelButton;
    private Button modifyButton;
    private Button deleteButton;
    private ArrayList<SongList> datalist;
    private static int pos;

    public SongListPopu(Context context, final int posi ,final  ArrayList<SongList> datalist) {
        super(context);
        this.posi = posi;
        this.datalist=datalist;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.songlist_operate_popup, null);
        cancelButton=(Button)mMenuView.findViewById(R.id.songlistcancel);
        modifyButton=(Button)mMenuView.findViewById(R.id.songlist_id_modify);
        deleteButton=(Button)mMenuView.findViewById(R.id.songlist_id_delete);
        cancelButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //销毁弹出框
                dismiss();
            }
        });
        this.setContentView(mMenuView);
        this.setWidth(ViewGroup.LayoutParams.FILL_PARENT);
        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        this.setBackgroundDrawable(dw);
        mMenuView.setOnTouchListener(new View.OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                int height = mMenuView.findViewById(R.id.activity_song_popup).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });
        modifyButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pos = posi;
                String songListName = datalist.get(posi).getSongListName();

                Log.i("tj", "onClick:updatebutton " + posi + songListName);
                up = MainActivity.getUp();
                up.show();
                up.settext(songListName);
                up.setDescripe();
                dismiss();
            }
        });
        deleteButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pos = posi;
                sp = MainActivity.getSp();
                sp.show();
                dismiss();
            }
        });
    }

    public static int getPos() {
        return pos;
    }
}

